package com.ima.controller;


import com.ima.model.Resume;
import com.ima.repository.ResumeRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 用户各种操作接口
 * Created by 符柱成 on 17-3-11.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private ResumeRepository resumeRepository;

    @RequestMapping(value = "/findList")
    public String test(Model model)  {
       List<Resume> resumes = resumeRepository.findAll();
        model.addAttribute("resumes",resumeRepository.findAll());
        return  "listView";
    }

    //删除数据
    @RequestMapping(value= {"/delete"})
    public String delete(Long id) {
        resumeRepository.delete(id);
        return "redirect:/user/findList";
}

//添加数据
    @RequestMapping(value= {"/add"})
    public String add(Resume resume) {
        resumeRepository.saveAndFlush(resume);
        return "redirect:/user/findList";
    }

    //更新数据
    @RequestMapping(value="/update")
    public String update(Resume resume) {

        resumeRepository.saveAndFlush(resume);

        return "redirect:/user/findList";
    }

    //去add.jsp
    @RequestMapping(value="/toAdd")
    public String toAdd() {
        return "addView";
    }

    //去update.jsp
    @RequestMapping(value="/toUpdate")
    public String findById(Model model, Long id ) {

        Resume resume = resumeRepository.findOne(id);

        model.addAttribute("resume", resume);
        return "updateView";
    }



}
